package com.butuh.uang.tuh.ang.ui;

import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.butuh.uang.tuh.ang.R;
import com.butuh.uang.tuh.ang.present.PCallOn;
import com.butuh.uang.tuh.ang.util.DecimalFormatUtil;
import com.butuh.uang.tuh.ang.util.OnClickLogUtils;


import butterknife.BindView;
import butterknife.OnClick;
import cn.droidlover.xdroidmvp.mvp.XActivity;

public class CallOurActivity extends XActivity<PCallOn> {

    @BindView(R.id.tv_message)
    TextView mTvMessage;
    @BindView(R.id.tv_email)
    TextView mTvEmail;


    @BindView(R.id.layout_data)
    LinearLayout mLayoutData;
    @BindView(R.id.layout_no_net)
    LinearLayout mLayoutNoNet;
    @BindView(R.id.layout_error)
    LinearLayout mLayoutError;
    @BindView(R.id.tv_error_message)
    TextView mTvErrorMessage;


    String yemianName = "HubungiKami";


    @Override
    public void initData(Bundle savedInstanceState) {
        OnClickLogUtils.onClickLog(this, "come-in-into", "[\\\"HubungiKami\\\"]",0);
        mDialog.Show();
        getP().getCallOn();
    }

    public void loadSuccess(String message) {
        mDialog.Dismiss();
        if (!TextUtils.isEmpty(message)) {
            mLayoutData.setVisibility(View.VISIBLE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.GONE);
            String mDecimalFormatStr = DecimalFormatUtil.htmlToText(message);
            String[] strs = mDecimalFormatStr.split("Email:");
            mTvMessage.setText(strs[0]);
            mTvEmail.setText(strs[1]);
        } else {
            mLayoutData.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.VISIBLE);
            mTvErrorMessage.setText("Saat ini tidak ada produk");
        }
    }


    public void loadError(int type, String message) {
        mDialog.Dismiss();
        if (type == 1) {
            mLayoutData.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.VISIBLE);
            mLayoutError.setVisibility(View.GONE);
        } else {
            mLayoutData.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.VISIBLE);
            mTvErrorMessage.setText(message);
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_call_our;
    }


    @OnClick({R.id.iv_back, R.id.tv_resume})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                OnClickLogUtils.onClickPermute(context, yemianName, "back", 0);
                break;
            case R.id.tv_resume:
                mDialog.Show();
                getP().getCallOn();
                OnClickLogUtils.onClickPermute(context, yemianName, "errorResume", 0);
                break;
        }
    }

    @Override
    public PCallOn newP() {
        return new PCallOn();
    }
}
